<?php

/*

Process Add Topic (add_topic.pro.php)

*/
ob_start();
$rank_check = 3;
include "global.inc.php";

if ($getInfo[premium] == "1")
{
	$colors = "$text_color, $bg_color, $bg_image.gif";
	$remember = fetch("SELECT background,text FROM remember_colors WHERE userid = '$userid'");
	if (($remember[background] != "$bg_color") OR ($remember[text] != "$text_color"))
	{
		$bg_color2 = ereg_replace("#", "", $bg_color);
		$text_color2 = ereg_replace("#", "", $text_color);

		mysql_query("DELETE FROM remember_colors WHERE userid = '$userid'");
		mysql_query("INSERT INTO remember_colors VALUES ('', '$userid', '$bg_color2', '$text_color2')");
	}
}

if ($rank < 4)
{
	$add_subject = badwords(strip_tags($add_subject,"<font>"));
}
else
{
	$add_subject = badwords(strip_tags($add_subject,"<b><i><u><font>"));
}

if (!$text_color) { $text_color = "#000000"; }

$add_message = format(smilies(badwords(strip_tags($add_message,"<b><i><u><a><font>"))),"$text_color");

if ((!$add_message) OR (!$add_subject))
{
	die(header(error("add_topic.php?game=$game", "Please do not leave the message or subject blank.")));
}

if ($rank < 5) { $sticky = 0; }

mysql_query("INSERT INTO forum_subjects2 (category,subject,author,last_post_by,last_post_at,sticky,game) VALUES ('$category','$add_subject','$userid','$userid','$timestamp','$sticky','$game')");

mysql_query("INSERT INTO forum_topics2 (id,message,timestamp,game,colors) VALUES ('" . mysql_insert_id() . "','$add_message','$timestamp','$game','$colors')");

$findCat = fetch("SELECT topics,posts FROM forum_cats2 WHERE id = '$category' AND game = '$game'");

mysql_query("UPDATE forum_cats2 SET last_post=$timestamp WHERE id = '$category' AND game = '$game'");
mysql_query("UPDATE forum_cats2 SET last_poster=$userid WHERE id = '$category' AND game = '$game'");
mysql_query("UPDATE members2 SET post_count=$getInfo[post_count]+1 WHERE username = '$username' AND game = '$game'");

header(error("view_cat.php?game=$game&id=$category","Your message has been posted."));

?>